package org.example.listener;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Slf4j
@Component
//@RabbitListener(queues = {"order", "test"}, concurrency = "1", executor = "rabbit-consumer-executor")
public class HelloReceiver {

    @Value("${ackFlag}")
    private boolean ackFlag;

//    @RabbitHandler
//    public void process1(int message, Channel channel) throws IOException, InterruptedException {
//        log.info("Receiver message info: {}", message);
////        Thread.sleep(2000);
//        // 自动ACK下进行手动ACK模式，即将消息发送回队列的尾部。
////        channel.basicPublish(message.getMessageProperties().getReceivedExchange(),
////                message.getMessageProperties().getReceivedRoutingKey(),
////                MessageProperties.PERSISTENT_TEXT_PLAIN,
////                message.getBody());
////        channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
////        channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
//        int i =1/0;
//        System.out.println("消息消费完成！");
////        if (ackFlag) {
////            channel.basicAck(sendMsg.getMessageProperties().getDeliveryTag(), false);
////        } else {
////             channel.basicReject(sendMsg.getMessageProperties().getDeliveryTag(), true);
////        }
////        Thread.sleep(3000);
//    }

//    @RabbitHandler
//    public void process2(String message, Channel channel, Message message111) throws IOException, InterruptedException {
//        Connection connection = channel.getConnection();
//        log.warn("delivery Tag is : {}", message111.getMessageProperties().getDeliveryTag());
//        log.info("Receiver message info: {}", message);
//        System.out.println("消息消费完成！");
//    }

}